//
//  JXFeedBackSelectView.m
//  JinXun
//
//  Created by Apple on 2023/2/20.
//

#import "JXFeedBackSelectView.h"

@interface JXFeedBackSelectView()

@property(nonatomic, strong) JXSelectViewHandle *selectViewHandle;
@property(nonatomic, strong) JXSecondHandDropViewSelectModel *selectResult;
@property(nonatomic, strong) NSArray <JXSecondHandDropViewSelectModel *>*datas;

@end



@implementation JXFeedBackSelectView

//MARK: - public

- (void)initConfig
{
    [self p_configSubviews];
}

- (void)configWithDatas:(NSArray <JXSecondHandDropViewSelectModel *>*)datas
{
    if(!datas) return;
    
    self.datas = datas;
    [self.selectViewHandle configWithDatas:datas];
}

//MARK: - system

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self){

    }
    return self;
}

//MARK: - FBCompleteProtocol

- (void)completeHandle:(NSObject *)obj
{
    if(!self.selectResult) {
        self.selectResult = self.datas.firstObject;
    }
    [self.nextStep completeHandle:[self netRequestParam:obj]];
}

//MARK: - private

- (NSDictionary *)netRequestParam:(NSObject *)obj
{
    NSDictionary *tmp_dic = (NSDictionary *)obj;
    if(!tmp_dic){
        tmp_dic = @{};
    }
    NSMutableDictionary *mutableDic = [tmp_dic mutableCopy];
    [mutableDic addEntriesFromDictionary:tmp_dic];
    mutableDic[@"id"] = [NSString stringWithFormat:@"%ld",(long)self.selectResult.idx];
    
    return [mutableDic copy];
}

- (void)p_configSubviews
{
    [self addSubview:self.selectViewHandle.view];
    
    [self.selectViewHandle.view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.right.mas_equalTo(self);
        make.edges.mas_equalTo(self);
    }];
}


//MARK: - set get

- (JXSelectViewHandle *)selectViewHandle
{
    if(!_selectViewHandle){
        _selectViewHandle = [JXSelectViewHandle new];
        @WeakObj(self);
        _selectViewHandle.selectBlock = ^(JXSecondHandDropViewSelectModel * _Nonnull selectModel) {
            @StrongObj(self);
            self.selectResult = selectModel;
        };
    }
    return _selectViewHandle;
}


@end
